﻿using System;
using NewLife.CommonEntity;
using NewLife.CommonEntity.Web;
using BingZi.HY.Core.Entities.System;
using BingZi.HY.Core.Message;
using BingZi.HY.Core.Enums;

namespace BingZi.HY.Core.BLL
{
    /// <summary>
    /// 页面基类
    /// </summary>
    /// <typeparam name="TAdminEntity"></typeparam>
    /// <typeparam name="TMenuEntity"></typeparam>
    public abstract class PageBase : WebPageBase<UserInfo, Menu>
    {
        /// <summary>
        /// 校验权限
        /// </summary>
        /// <returns></returns>
        public override Boolean CheckPermission()
        {
            if (base.CheckPermission()) return true;

            Response.Redirect("../Login.aspx");
            return false;
        }

        /// <summary>
        /// 根据CMD检测权限
        /// </summary>
        /// <param name="CMD">CMD值</param>
        public  void CheckPagePermission(string CMD)
        {
            switch (CMD)
            {
                case "List":
                    CheckPermissionVoid(PermissionFlags.List);
                    break;
                case "New":
                    CheckPermissionVoid(PermissionFlags.New);
                    break;
                case "Edit":
                    CheckPermissionVoid(PermissionFlags.Edit);
                    break;
                case "OrderBy":
                    CheckPermissionVoid(PermissionFlags.Edit);
                    break;
                case "Move":
                    CheckPermissionVoid(PermissionFlags.Delete);
                    break;
                case "Delete":
                    CheckPermissionVoid(PermissionFlags.Delete);
                    break;
            }
        }

        /// <summary>
        /// 检测权限(出提示框)
        /// </summary>
        /// <param name="PT"></param>
        public  void CheckPermissionVoid(PermissionFlags PT)
        {
            if (!CheckButtonPermission(PT))
            {
                EventMessage.MessageBox(2, "禁止访问", "无权限执行当前操作!", Icon_Type.Error, "history.back();", UrlType.JavaScript);
            }
        }

        /// <summary>
        /// 检测权限
        /// </summary>
        /// <param name="PT"></param>
        /// <returns></returns>
        public   bool CheckButtonPermission(PermissionFlags PT)
        {
            return Acquire(PT);
        }
     


    }
}